/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package views;

import healthcare.coursework.model.TestSamples;
import healthcare.coursework.model.TestSamplesPK;
import healthcare.coursework.service.AppointmentService;
import java.util.Date;
import org.zkoss.zk.ui.event.Event;
import org.zkoss.zk.ui.util.GenericAutowireComposer;
import org.zkoss.zul.Button;
import org.zkoss.zul.Groupbox;
import org.zkoss.zul.ListModelList;
import org.zkoss.zul.Listbox;

/**
 *
 * @author Administrator
 */
public class ViewLabTestings extends GenericAutowireComposer {

    private Listbox labTestingDataListView;
    private AppointmentService appointmentService = util.Utility.getUtility().getAppointmentService();
    private Button book;
    private Button cancel;
    private Groupbox gbUtility;

    public void onLoadList(Event e) {
        book.setVisible(false);
        cancel.setVisible(false);
        labTestingDataListView.setModel(new ListModelList(appointmentService.listOfRequestLabTesting()));
    }

    public void onCancelAppointment(Event e) {
        TestSamplesPK pk = ((TestSamples) labTestingDataListView.getSelectedItem().getValue()).getTestSamplesPK();
        appointmentService.cancelAppointmentForLab(pk);
        onLoadList(e);
    }

    public void onBookAppointment(Event e) {
        TestSamplesPK pk = ((TestSamples) labTestingDataListView.getSelectedItem().getValue()).getTestSamplesPK();
        appointmentService.bookAppointmentForLab(pk);
        onLoadList(e);
    }

     public void onLoadButton(Event e){
         TestSamples ts=((TestSamples) labTestingDataListView.getSelectedItem().getValue());
       String status= ts.getRequestStatus().toString();
       if(status.equals("pending"))
       {
            gbUtility.setVisible(true);
       }
       else if(status.equals("admitted"))
       {
           gbUtility.setVisible(false);
       }
       else
       {
           if(ts.getTrackedDate().before(new Date()))
                book.setVisible(true);
           else
                book.setVisible(false);
           cancel.setVisible(false);
       }

    }
}
